<template>
  <nav class="navbar">
    <div class="logo">
      <router-link to="/">电影世界</router-link>
    </div>
    
    <div class="nav-links">
      <router-link to="/">电影列表</router-link>
      <router-link to="/add-movie">添加电影</router-link>
      <a href="https://gitee.com/luren98/final-film.git" target="_blank">码云仓库</a>
    </div>
    
    <div class="user-actions">
      <template v-if="userStore.isLoggedIn">
        <span class="welcome">欢迎, {{ userStore.userInfo?.username }}</span>
        <button @click="logout" class="btn-logout">退出</button>
      </template>
      <template v-else>
        <router-link to="/login" class="btn-login">登录</router-link>
        <router-link to="/register" class="btn-register">注册</router-link>
      </template>
    </div>
  </nav>
</template>

<script setup lang="ts">
import { useUserStore } from '../store/user'
import { useRouter } from 'vue-router'

const userStore = useUserStore()
const router = useRouter()

const logout = () => {
  userStore.logout()
  router.push({ name: 'login' })
}
</script>

<style scoped lang="scss">
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 40px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.logo {
  a {
    color: white;
    font-size: 24px;
    font-weight: bold;
    text-decoration: none;
    
    &:hover {
      color: #3498db;
    }
  }
}

.nav-links {
  display: flex;
  gap: 30px;
  
  a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s;
    font-size: 18px;
    
    &:hover, &.router-link-exact-active {
      color: white;
    }
    
    &.router-link-exact-active {
      position: relative;
      
      &::after {
        content: '';
        position: absolute;
        bottom: -5px;
        left: 0;
        right: 0;
        height: 2px;
        background: #3498db;
      }
    }
  }
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 15px;
  
  .welcome {
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
  }
}

.btn-login, .btn-register, .btn-logout {
  padding: 8px 20px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  text-decoration: none;
}

.btn-login {
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  
  &:hover {
    background: rgba(255, 255, 255, 0.1);
  }
}

.btn-register {
  background: #3498db;
  color: white;
  border: none;
  
  &:hover {
    background: #2980b9;
  }
}

.btn-logout {
  background: #e74c3c;
  color: white;
  border: none;
  
  &:hover {
    background: #c0392b;
  }
}

@media (max-width: 992px) {
  .nav-links {
    gap: 20px;
  }
}

@media (max-width: 768px) {
  .navbar {
    flex-wrap: wrap;
    padding: 15px;
  }
  
  .logo {
    order: 1;
    width: 100%;
    text-align: center;
    margin-bottom: 15px;
  }
  
  .nav-links {
    order: 3;
    width: 100%;
    justify-content: center;
    margin-top: 15px;
    gap: 15px;
  }
  
  .user-actions {
    order: 2;
  }
}

@media (max-width: 576px) {
  .nav-links {
    flex-wrap: wrap;
    
    a {
      font-size: 16px;
    }
  }
  
  .btn-login, .btn-register, .btn-logout {
    padding: 6px 15px;
    font-size: 14px;
  }
}
</style>